package com.tulele.vtool.wechat.handler;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Maps;
import com.tulele.vtool.feignclient.FileFeignClient;
import com.tulele.vtool.mapper.KeywordDetailLogMapper;
import com.tulele.vtool.model.*;
import com.tulele.vtool.model.combinedEntity.SearchBrandInfo;
import com.tulele.vtool.model.combinedEntity.UserBrandCombinedInfo;
import com.tulele.vtool.model.logEntity.KeyWrodInfo;
import com.tulele.vtool.model.respEntity.ReturnCode;
import com.tulele.vtool.model.respEntity.WxArticleSpiderResult;
import com.tulele.vtool.sensitive.SensitiveFilter;
import com.tulele.vtool.service.*;
import com.tulele.vtool.task.async.SendkefuMsgAsyncTask;
import com.tulele.vtool.utils.*;
import com.tulele.vtool.wechat.builder.ImageBuilder;
import com.tulele.vtool.wechat.builder.TextBuilder;
import com.tulele.vtool.wechat.service.WeixinService;
import com.tulele.vtool.wechat.service.WeixinServiceDL;
import io.lkt.common.dto.ArticleInfoTemp;
import io.lkt.common.utils.WebSpiderThreadUtil;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateData;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

import java.io.*;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.nio.file.StandardCopyOption;
import java.util.*;

//接收用户消息
@Component
@Slf4j
public class MsgHandler extends AbstractHandler {

    @Autowired
    private IUserInfoService userInfoService;

    @Autowired
    private IArticleInfoService articleInfoService;

//    @Autowired
//    private PlatformSysInfoConfig platformSysInfoConfig;

    @Autowired
    private SendkefuMsgAsyncTask sendkefuMsgAsyncTask;

    @Autowired
    private RedisCacheUtil redisCacheUtil;

    @Autowired
    private IBrandInfoService brandInfoService;

    @Autowired
    private IUserBrandInfoService userBrandInfoService;

//    @Autowired
//    private FileFeignClient fileFeignClient;

//    @Value("${wxShareImgPath}")
//    private String wxShareImgPath;
//
//    @Value("${spring.profiles.active}")
//    private String springProfilesActive;

    private static final String TRICKORTREAT = "TRICKORTREAT:";

    @Autowired
    private IUserPunchClockInfoService userPunchClockInfoService;

    @Autowired
    private KeywordDetailLogMapper keywordDetailLogMapper;

    @Autowired
    @Lazy
    protected MenuHandler menuHandler;

    @Autowired
    private SysGzhService sysGzhService;

    /**
     * 服务对象
     */
    @Autowired
    private BMessageKefuService bMessageKefuService;

    @Autowired
    private UserGroupGzhService userGroupGzhService;

    @SneakyThrows
    @Override
    public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage,
                                    Map<String, Object> context, WxMpService wxMpService,
                                    WxSessionManager sessionManager) {

        WeixinServiceDL weixinService = (WeixinServiceDL) wxMpService;
        PlatformSysInfo platformSysInfoConfig = sysGzhService.getPlatformSysInfoByAppId(weixinService.getWxMpConfigStorage().getAppId());
        SysGzh sysGzh = platformSysInfoConfig.getSysGzh();
        String springProfilesActive = sysGzh.getGzhCode();
        String wxShareImgPath = platformSysInfoConfig.getWxShareImgPath();

        //if (!wxMessage.getMsgType().equals(WxConsts.XmlMsgType.EVENT)) {
        //TODO 可以选择将消息保存到本地
        //}

        //TODO 组装回复消息
        //String content = "回复信息内容";
        //return new TextBuilder().build(content, wxMessage, weixinService);

        //判断用户发送的消息是否为空
        String userSendContent = wxMessage.getContent();
        if (StringUtils.isBlank(userSendContent)) {
            return null;
        }

        //获取发送方OPENID
        String fromUserOpenId = wxMessage.getFromUser();
        log.info("[MsgFromUserOpenId] = " + fromUserOpenId);

//        if (springProfilesActive.equals("prodqkb") && StringUtils.isNotBlank(userSendContent) && !userSendContent.trim().equals("客服")) {//启客宝
//
//            menuHandler.pushMsg("[握手] 您好，由于公众号升级，请关注新号继续使用\n\n<a href=\"weixin://bizmsgmenu?msgmenucontent=客服&msgmenuid=+++\">\uD83C\uDF37 有任何问题请回复【客服】解答</a>"
//                    , wxMessage.getFromUser(), weixinService);
//
//            String[] gzhArr = {"kdbw_qrcode.png"};
//
//            int index = (int) (Math.random() * gzhArr.length);
//
//            String clickSendImg = platformSysInfoConfig.getWxShareImgPath() + gzhArr[index];
//            menuHandler.mySendKefuImg(wxMessage, weixinService, clickSendImg, 0);
//            return null;
//        }

        WxMpXmlOutMessage rewMsg = null;

        KeyWrodInfo keyWrodInfo = new KeyWrodInfo();
        keyWrodInfo.setKeyword(wxMessage.getContent());
        keyWrodInfo.setGzhCode(springProfilesActive);
        keyWrodInfo.setOpenid(fromUserOpenId);
        keyWrodInfo.setCreateTime(new Date());
        if (wxMessage.getAllFieldsMap().get("bizmsgmenuid") != null) {//20210623 添加bizmsgmenuid，区分是点击 还是 输入回复
            keyWrodInfo.setBizmsgmenuid(wxMessage.getAllFieldsMap().get("bizmsgmenuid").toString());
        } else {
            keyWrodInfo.setBizmsgmenuid("");
        }
        keywordDetailLogMapper.addKeyWrodInfo(keyWrodInfo);


        UserInfo userInfo = userInfoService.getUserBaseInfoByOpenId(fromUserOpenId);
        if (userInfo == null) {
            //return null;

            try {

                String msg = SysConstant.JH_PUSH_MSG.replace(SysConstant.frontDomain, platformSysInfoConfig.getFrontDomain());
                if(userInfo.getPhoneModel().equals(SysConstant.IOS)){
                    msg =ToolUtil.handleMsgmenuidByIOS(msg);
                }
                rewMsg = new TextBuilder().build(msg, wxMessage, weixinService);
            } catch (Exception e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }

            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
            return rewMsg;

        }

        //region （公众号做通）20210902
        UserGroupOpenId userGroupOpenId = userGroupGzhService.getUserGroupUserId(springProfilesActive, fromUserOpenId);
        if (userGroupOpenId != null && userGroupOpenId.getUserId() != null) {
            userInfo.setUserId(userGroupOpenId.getUserId());
        }
        //endregion

        //region 如果用户是点击回复,10秒给他推送提醒 20210908
        try {
            if (keyWrodInfo.getBizmsgmenuid() != null && !keyWrodInfo.getBizmsgmenuid().equals("")) {
                //menuHandler.mySendKefuMessage_10sec(wxMessage, weixinService, userInfo, springProfilesActive);
                sendkefuMsgAsyncTask.send10secKefuMsg(userInfo,platformSysInfoConfig,10000);
            }
        } catch (Exception e) {
        }
        //endregion

        //判断用户发送的消息是否为微信公众号文章链接
//        String userSendContent = wxMessage.getContent();
//        if (StringUtils.isBlank(userSendContent)) {
//            return null;
//        }


        keyWrodInfo.setUserId(userInfo.getUserId());
        keyWrodInfo.setReplyStatus(1);
        keyWrodInfo.setErrMsg("成功");


        //20200609
        redisCacheUtil.removeSingleCache(userInfo.getUserId() + "lookArticleWxPushTimes");


        log.info("[userSendContent***] = " + userSendContent);
        if (StringUtils.isNotBlank(userSendContent) && (userSendContent.trim().equals("查看原因") || userSendContent.trim().equals("10"))) {  //24小时提醒 20200219
            log.info("[userSendContent***查看原因] = ");
            try {
                String msg = SysConstant.PROMPTING_24_PUSH_MSG;
                if(userInfo.getPhoneModel().equals(SysConstant.IOS)){
                    msg =ToolUtil.handleMsgmenuidByIOS(msg);
                }
                rewMsg = new TextBuilder().build(msg, wxMessage, weixinService);
            } catch (Exception e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }

            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
            return rewMsg;
        }

        if (StringUtils.isNotBlank(userSendContent) && (userSendContent.trim().equals("获取爆文") || userSendContent.trim().equals("换一批") || userSendContent.trim().equals("11"))) {
            log.info("[userSendContent***获取爆文] = ");
            try {
                sendkefuMsgAsyncTask.sendAttentionRemindKefuMsg(userInfo.getUserId().toString(), platformSysInfoConfig);
            } catch (Exception e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }

            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
            return null;
        }

        if (StringUtils.isNotBlank(userSendContent) && (userSendContent.trim().equals("获取视频"))) {
            log.info("[userSendContent***获取视频] = ");
            try {
                sendkefuMsgAsyncTask.sendVideoKefuMsg(userInfo.getUserId().toString(), platformSysInfoConfig);
            } catch (Exception e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }

            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
            return null;
        }

        if (StringUtils.isNotBlank(userSendContent) && (userSendContent.trim().equals("test10sec"))) {
            log.info("[userSendContent***test10sec] = ");
            try {
                sendkefuMsgAsyncTask.send10secKefuMsg(userInfo, platformSysInfoConfig,10000);
            } catch (Exception e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }

            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
            return null;
        }

        if (StringUtils.isNotBlank(userSendContent) && (userSendContent.trim().equals("唤醒小编") || userSendContent.trim().equals("9"))) {
            try {
                //rewMsg = new TextBuilder().build("\uD83D\uDC96推送已激活，小编将在48小时内持续给您发送文章噢！", wxMessage, weixinService);
                sendkefuMsgAsyncTask.sendAttentionRemindKefuMsg(userInfo.getUserId().toString(), platformSysInfoConfig);
            } catch (Exception e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }

            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
            return rewMsg;
        }

        if (StringUtils.isNotBlank(userSendContent) && (userSendContent.trim().equals("领取爆文"))) {
            try {
                menuHandler.receiveArticle(userInfo, weixinService, platformSysInfoConfig);
            } catch (Exception e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }

            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
            return rewMsg;
        }

        if (StringUtils.isNotBlank(userSendContent) && (userSendContent.trim().equals("回复激活"))) {
            try {
                menuHandler.mySendKefuMessage_huifujihuo(wxMessage, weixinService, userInfo);
            } catch (Exception e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }

            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
            return rewMsg;
        }

        if (StringUtils.isNotBlank(userSendContent) && (userSendContent.trim().contains("客户") || userSendContent.trim().equals("1"))) {
            //log.info("[userSendContent***查看原因] = ");
            try {
                String msg = SysConstant.KH_PUSH_MSG.replace(SysConstant.frontDomain, platformSysInfoConfig.getFrontDomain());
                if(userInfo.getPhoneModel().equals(SysConstant.IOS)){
                    msg =ToolUtil.handleMsgmenuidByIOS(msg);
                }
                rewMsg = new TextBuilder().build(msg, wxMessage, weixinService);

                //文章图文消息推送
//                WxMpKefuMessage.WxArticle wxArticle = new WxMpKefuMessage.WxArticle();
//                wxArticle.setTitle("你知道谁在关注你吗？【客户追踪】精准分析客户意向");
//                wxArticle.setDescription("谁看过你的文章帮你实时追踪朋友圈潜在客户，获客更高效！");
//                wxArticle.setPicUrl("https://zktuistatic.oss-cn-shenzhen.aliyuncs.com/wxTouXiang/khzz.png");
//
//                wxArticle.setUrl(platformSysInfoConfig.getCustomerMenuUrl());
//                WxMpKefuMessage testMsg = WxMpKefuMessage.NEWS().addArticle(wxArticle).toUser(wxMessage.getFromUser()).build();
//
//                weixinService.getKefuService().sendKefuMessage(testMsg);

            } catch (Exception e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }

            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
            return rewMsg;
        }

        if (StringUtils.isNotBlank(userSendContent) && (userSendContent.trim().contains("我的表单"))) {
            //log.info("[userSendContent***查看原因] = ");
            try {
                String msg = SysConstant.TABLE_PUSH_MSG.replace(SysConstant.frontDomain, platformSysInfoConfig.getFrontDomain());
                if(userInfo.getPhoneModel().equals(SysConstant.IOS)){
                    msg =ToolUtil.handleMsgmenuidByIOS(msg);
                }
                rewMsg = new TextBuilder().build(msg, wxMessage, weixinService);

                //文章图文消息推送
//                WxMpKefuMessage.WxArticle wxArticle = new WxMpKefuMessage.WxArticle();
//                wxArticle.setTitle("你知道谁在关注你吗？【客户追踪】精准分析客户意向");
//                wxArticle.setDescription("谁看过你的文章帮你实时追踪朋友圈潜在客户，获客更高效！");
//                wxArticle.setPicUrl("https://zktuistatic.oss-cn-shenzhen.aliyuncs.com/wxTouXiang/khzz.png");
//
//                wxArticle.setUrl(platformSysInfoConfig.getCustomerMenuUrl());
//                WxMpKefuMessage testMsg = WxMpKefuMessage.NEWS().addArticle(wxArticle).toUser(wxMessage.getFromUser()).build();
//
//                weixinService.getKefuService().sendKefuMessage(testMsg);

            } catch (Exception e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }

            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
            return rewMsg;
        }

        if (StringUtils.isNotBlank(userSendContent) && userSendContent.trim().contains("新手学堂") ) {
            //log.info("[userSendContent***查看原因] = ");
            try {
                WxMpKefuMessage.WxArticle wxArticle = new WxMpKefuMessage.WxArticle();
                wxArticle.setTitle("双特·新手学堂【微信收藏】");
                wxArticle.setDescription("小白变大咖，提高收益必看！");
                wxArticle.setPicUrl("https://zktuistatic.oss-cn-shenzhen.aliyuncs.com/wxTouXiang/xsxt.png");

                wxArticle.setUrl(platformSysInfoConfig.getSysGzh().getRealmResource()+"pages/Billing/Billingassistant.html?userId="+userInfo.getUserId());
                WxMpKefuMessage testMsg = WxMpKefuMessage.NEWS().addArticle(wxArticle).toUser(wxMessage.getFromUser()).build();

                weixinService.getKefuService().sendKefuMessage(testMsg);

            } catch (Exception e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }

            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
            return rewMsg;
        }


        // 含有自己平台的视频链接
        if (StringUtils.isNotBlank(userSendContent) && userSendContent.contains("http") && userSendContent.contains("/pages/video/index.html?") && userSendContent.contains("articleId=")) {

            WxMpKefuMessage message = WxMpKefuMessage.TEXT().toUser(wxMessage.getFromUser()).content("视频正在创建中，请稍后......").build();
            try {
                weixinService.getKefuService().sendKefuMessage(message);
            } catch (WxErrorException e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }

            try {
                userSendContent = userSendContent.replaceAll("//pages", "/pages");
                // 过滤链接中的中文
                String articleUrls = ToolUtil.findUrlByStr(userSendContent);

                // 拿到链接中的视频 id
                String articleIds = ToolUtil.getParam(articleUrls, "articleId");

                if (StringUtils.isNotBlank(articleIds)) {
                    ArticleInfo articleInfo = articleInfoService.getArticleDetailInfo(Integer.parseInt(articleIds));
                    if (articleInfo != null) {
                        //文章图文消息推送
                        WxMpKefuMessage.WxArticle wxArticle = new WxMpKefuMessage.WxArticle();
                        wxArticle.setTitle(articleInfo.getArticleTitle());
                        wxArticle.setDescription(articleInfo.getArticleDesc());
                        wxArticle.setPicUrl(articleInfo.getArticleImgUrl()+"?"+SysConstant.OSS_PAR_80_80);

                        //拼接链接地址
                        String accessUrl = platformSysInfoConfig.getFrontDomain() + "pages/video/index.html?articleId=" + articleIds + "&viewType=2";

                        wxArticle.setUrl(accessUrl);
                        WxMpKefuMessage testMsg = WxMpKefuMessage.NEWS().addArticle(wxArticle).toUser(wxMessage.getFromUser()).build();

                        weixinService.getKefuService().sendKefuMessage(testMsg);
                    }
                }
            } catch (WxErrorException e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }

            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
            return null;
        }

        // 含有自己平台文章链接
        if (StringUtils.isNotBlank(userSendContent) && userSendContent.contains("http") && userSendContent.contains("/pages/article/detail.html?") && userSendContent.contains("articleId=")) {

            WxMpKefuMessage message = WxMpKefuMessage.TEXT().toUser(wxMessage.getFromUser()).content("文章正在创建中，请稍后......").build();
            try {
                weixinService.getKefuService().sendKefuMessage(message);
            } catch (WxErrorException e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }

            try {
                // 过滤链接中的中文
                String articleUrls = ToolUtil.findUrlByStr(userSendContent);

                // 拿到链接中的文章 id
                String articleIds = ToolUtil.getParam(articleUrls, "articleId");

                if (StringUtils.isNotBlank(articleIds)) {
                    ArticleInfo articleInfo = articleInfoService.getArticleDetailInfo(Integer.parseInt(articleIds));
                    if (articleInfo != null) {
                        //文章图文消息推送
                        WxMpKefuMessage.WxArticle wxArticle = new WxMpKefuMessage.WxArticle();
                        wxArticle.setTitle(articleInfo.getArticleTitle());
                        wxArticle.setDescription(articleInfo.getArticleDesc());
                        wxArticle.setPicUrl(articleInfo.getArticleImgUrl()+"?"+SysConstant.OSS_PAR_80_80);

                        //拼接链接地址
                        String accessUrl = platformSysInfoConfig.getFrontDomain() + "pages/article/detail.html?articleId=" + articleIds + "&t=2";

                        wxArticle.setUrl(accessUrl);
                        WxMpKefuMessage testMsg = WxMpKefuMessage.NEWS().addArticle(wxArticle).toUser(wxMessage.getFromUser()).build();

                        weixinService.getKefuService().sendKefuMessage(testMsg);
                    }
                }
            } catch (WxErrorException e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }

            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
            return null;
        }

        // 含有微信公众号文章链接
        if (StringUtils.isNotBlank(userSendContent) && userSendContent.contains("mp.weixin.qq.com")) {

            // 查询会员状态。
            Integer vipStatus = Optional.ofNullable(userInfoService.getUserVipStatus(userInfo.getUserId())).orElse(0);

            if (vipStatus == null || vipStatus == 0) {
                try {
                    String msg = SysConstant.PUSH_MEMBER_BENEFITS_FORARTICLE.replace(SysConstant.frontDomain, platformSysInfoConfig.getFrontDomain());
                    if(userInfo.getPhoneModel().equals(SysConstant.IOS)){
                        msg =ToolUtil.handleMsgmenuidByIOS(msg);
                    }
                    rewMsg = new TextBuilder().build(msg, wxMessage, weixinService);
                } catch (Exception e) {
                    keyWrodInfo.setReplyStatus(2);
                    keyWrodInfo.setErrMsg(e.getMessage());
                }

                keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
                return rewMsg;
            }

            WxMpKefuMessage message = WxMpKefuMessage.TEXT().toUser(wxMessage.getFromUser()).content("文章正在创建中，请稍后......").build();
            try {
                weixinService.getKefuService().sendKefuMessage(message);
            } catch (WxErrorException e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }

            try {
                // 过滤链接中的中文
                userSendContent = ToolUtil.findUrlByStr(userSendContent);

                //微信公众号文章 链接 变 文章
                ArticleInfoTemp item = WebSpiderThreadUtil.getWeiXinPage(userSendContent.replaceAll("\"", ""));

                SensitiveFilter titleFilter = new SensitiveFilter(new BufferedReader(new InputStreamReader(this.getClass().getClassLoader().getResourceAsStream("sensi_words.txt"), StandardCharsets.UTF_8)));
                //SensitiveFilter descFilter = SensitiveFilter.DEFAULT;
                // 待过滤的句子
                String articleTitle = item.getArticleTitle();
                String articleDesc = item.getArticleDesc();

                // 进行过滤
                String titleFilted = titleFilter.filter(articleTitle, '*');
                String descFilted = titleFilter.filter(articleDesc, '*');

                // 如果未过滤，则返回输入的String引用
                if (titleFilted.contains("**") || descFilted.contains("**")) {

                    //找出可能第一个敏感词语
                    int length = Math.min((titleFilted + descFilted).length(), (articleTitle + articleDesc).length());
                    int pos = 0;
                    while (pos < length) {
                        if (0 != ((titleFilted + descFilted).charAt(pos) ^ (articleTitle + articleDesc).charAt(pos))) {
                            break;
                        }
                        pos++;
                    }

                    String msg="您好，标题或配文中含有敏感关键字【" + (articleTitle + articleDesc).substring(pos, pos + 2) + "】哦，如果您有添加其他类型文章的需求，请回复【客服】添加客服微信，我们客服手动帮您添加。";
                    if(userInfo.getPhoneModel().equals(SysConstant.IOS)){
                        msg =ToolUtil.handleMsgmenuidByIOS(msg);
                    }
                    return new TextBuilder().build(msg, wxMessage, weixinService);
                } else {

                    ArticleInfo articleInfo = new ArticleInfo();
                    articleInfo.setArticleTitle(item.getArticleTitle());
                    articleInfo.setArticleDesc(item.getArticleDesc());
                    articleInfo.setArticleImgUrl(item.getArticleImgUrl());
                    articleInfo.setArticleContent(item.getArticleContent());


                    articleInfo.setUserId(userInfo.getUserId());
                    articleInfo.setArticleSource(2);
                    articleInfo.setArticleStatus(1);
                    articleInfo.setSpiderProcessStatus(1);
                    articleInfo.setArticleVersionNum(2);
                    articleInfo.setCreateTime(DateUtil.getCurDate());
                    int articleId = articleInfoService.addWechatArticleInfo(articleInfo);

                    //查询文章
//                ArticleInfo articleInfo = articleInfoService.getArticleDetailByInfo(articleId);

                    //文章图文消息推送
                    WxMpKefuMessage.WxArticle wxArticle = new WxMpKefuMessage.WxArticle();
                    wxArticle.setTitle(item.getArticleTitle());
                    wxArticle.setDescription(item.getArticleDesc());
                    wxArticle.setPicUrl(item.getArticleImgUrl()+"?"+SysConstant.OSS_PAR_80_80);

                    //拼接链接地址
                    String accessUrl = platformSysInfoConfig.getShareDomainUrl() + "pages/article/detail.html?articleId=" + articleId + "&userId=" + articleInfo.getUserId() + "&t=2";

                    wxArticle.setUrl(accessUrl);
                    WxMpKefuMessage testMsg = WxMpKefuMessage.NEWS().addArticle(wxArticle).toUser(wxMessage.getFromUser()).build();

                    weixinService.getKefuService().sendKefuMessage(testMsg);
                }
            } catch (WxErrorException e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }

            return null;
        }

        // 含有抖音链接
        if (StringUtils.isNotBlank(userSendContent) && userSendContent.contains("v.douyin.com")) {
            // 查询会员状态。
            Integer vipStatus = Optional.ofNullable(userInfoService.getUserVipStatus(userInfo.getUserId())).orElse(0);

            Integer NotVipVideoCount = 0;

            // 如果不是会员，最多上传三次。
            if (vipStatus == null || vipStatus == 0) {

                vipStatus = 0;
                NotVipVideoCount = (Integer) Optional.ofNullable(redisCacheUtil.getCacheObject(TRICKORTREAT + userInfo.getUserId().toString())).orElse(0);

                if (NotVipVideoCount >= 3) {
                    try {
                        String msg = SysConstant.PUSH_MEMBER_BENEFITS_FORVIDEO.replace(SysConstant.frontDomain, platformSysInfoConfig.getFrontDomain());
                        if(userInfo.getPhoneModel().equals(SysConstant.IOS)){
                            msg =ToolUtil.handleMsgmenuidByIOS(msg);
                        }
                        rewMsg = new TextBuilder().build(msg, wxMessage, weixinService);
                    } catch (Exception e) {
                        keyWrodInfo.setReplyStatus(2);
                        keyWrodInfo.setErrMsg(e.getMessage());
                    }

                    keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
                    return rewMsg;
                }
            }

            WxMpKefuMessage message = WxMpKefuMessage.TEXT().toUser(wxMessage.getFromUser()).content("视频正在创建中，请稍后......").build();

            try {
                weixinService.getKefuService().sendKefuMessage(message);
            } catch (WxErrorException e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }

            try {
                //抖音链接变文章
                ArticleInfo articleInfoDto = VideoParse.parseUrl(userSendContent, userInfo.getUserId().toString());

                //添加视频
                int videoArticleId = articleInfoService.addMaterialVideoByDouDouInfo(articleInfoDto);

                //查询文章
                ArticleInfo articleInfo = articleInfoService.getArticleDetailByInfo(videoArticleId);

                //文章图文消息推送
                WxMpKefuMessage.WxArticle wxArticle = new WxMpKefuMessage.WxArticle();
                wxArticle.setTitle(articleInfo.getArticleTitle());
                wxArticle.setDescription(articleInfo.getArticleDesc());
                wxArticle.setPicUrl(articleInfo.getArticleImgUrl()+"?"+SysConstant.OSS_PAR_80_80);

                //拼接链接地址
                String accessUrl = platformSysInfoConfig.getFrontDomain() + "pages/video/index.html?articleId=" + videoArticleId + "&userId=" + articleInfo.getUserId() + "&viewType=2";

                wxArticle.setUrl(accessUrl);
                WxMpKefuMessage testMsg = WxMpKefuMessage.NEWS().addArticle(wxArticle).toUser(wxMessage.getFromUser()).build();

                weixinService.getKefuService().sendKefuMessage(testMsg);
            } catch (WxErrorException e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }

            return null;
        }

        if (StringUtils.isNotBlank(userSendContent) && userSendContent.trim().toLowerCase().startsWith("http")) {

            if (!userSendContent.trim().toLowerCase().startsWith("https://mp.weixin.qq.com")) {


                return new TextBuilder().build("您好，目前仅支持微信公众号文章哦，如果您有添加其他类型文章的需求，请回复【客服】添加客服微信，我们客服手动帮您添加。", wxMessage, weixinService);

            } else {

                WxMpKefuMessage message = WxMpKefuMessage.TEXT().toUser(wxMessage.getFromUser()).content("文章正在创建中，请稍后......").build();
                try {
                    weixinService.getKefuService().sendKefuMessage(message);
                } catch (WxErrorException e) {
                    keyWrodInfo.setReplyStatus(2);
                    keyWrodInfo.setErrMsg(e.getMessage());
                }

                try {
                    Document doc = Jsoup.parse(new URL(userSendContent), 5000);
                    log.info("**********_doc:" + doc.toString());
                } catch (IOException e) {
                    keyWrodInfo.setReplyStatus(2);
                    keyWrodInfo.setErrMsg(e.getMessage());
                }

                Map<String, String> reqMap = Maps.newHashMap();
                reqMap.put("wxArticleUrl", userSendContent);

                String finalReqUrl = platformSysInfoConfig.getWxArticleSpiderUrl();

                String wxSpdiderResult = HttpClientUtils.sendPost(finalReqUrl, (JSONObject) JSONObject.toJSON(reqMap));

                if (StringUtils.isBlank(wxSpdiderResult)) {

                    WxMpKefuMessage bzcMessage = WxMpKefuMessage.TEXT().toUser(wxMessage.getFromUser()).content("文章内容中可能包括音视频内容，平台暂不支持......").build();
                    try {
                        weixinService.getKefuService().sendKefuMessage(bzcMessage);
                    } catch (WxErrorException e) {
                        keyWrodInfo.setReplyStatus(2);
                        keyWrodInfo.setErrMsg(e.getMessage());
                    }

                    return null;
                }

                WxArticleSpiderResult wxArticleSpiderResult = JSONObject.parseObject(wxSpdiderResult, WxArticleSpiderResult.class);

                int resutCode = wxArticleSpiderResult.getCode();

                if (resutCode == ReturnCode.NORMAL_SUCC) {

                    //查询用户是否已经添加了该文章
                    String articleTitle = wxArticleSpiderResult.getData().getArticle_title();
                    ArticleInfo articleInfoInDB = articleInfoService.getUserAddedWxArticleInfoByTitle(userInfo.getUserId(), articleTitle);

                    //调用接口获取文章标题、详情、描述、缩略图
                    ArticleInfo articleInfo = new ArticleInfo();
                    if (articleInfoInDB != null && articleInfoInDB.getId() != null) {

                        articleInfo = articleInfoInDB;

                    } else {
                        // 使用默认单例（加载默认词典）
                        SensitiveFilter titleFilter = new SensitiveFilter(new BufferedReader(new InputStreamReader(this.getClass().getClassLoader().getResourceAsStream("sensi_words.txt"), StandardCharsets.UTF_8)));
                        //SensitiveFilter descFilter = SensitiveFilter.DEFAULT;
                        // 待过滤的句子
                        String articleDesc = wxArticleSpiderResult.getData().getArticle_content();

                        // 进行过滤
                        String titleFilted = titleFilter.filter(articleTitle, '*');
                        String descFilted = titleFilter.filter(articleDesc, '*');

                        // 如果未过滤，则返回输入的String引用
                        if (titleFilted.contains("**") || descFilted.contains("**")) {

                            //找出可能第一个敏感词语
                            int length = Math.min((titleFilted + descFilted).length(), (articleTitle + articleDesc).length());
                            int pos = 0;
                            while (pos < length) {
                                if (0 != ((titleFilted + descFilted).charAt(pos) ^ (articleTitle + articleDesc).charAt(pos))) {
                                    break;
                                }
                                pos++;
                            }

                            //		System.out.println(filted.substring(pos));
                            //      System.out.println("敏感词可能为：" + (articleTitle+articleDesc).substring(pos,pos+3));

                            return new TextBuilder().build("您好，标题或文章中含有敏感关键字【" + (articleTitle + articleDesc).substring(pos, pos + 2) + "】哦，如果您有添加其他类型文章的需求，请回复【客服】添加客服微信，我们客服手动帮您添加。", wxMessage, weixinService);
                        } else {
                            articleInfo.setArticleTitle(articleTitle);
                            //articleInfo.setArticleDesc(wxArticleSpiderResult.getData().getArticle_desc());//屏蔽于 20200504
                            articleInfo.setArticleDesc("");
                            articleInfo.setArticleImgUrl(wxArticleSpiderResult.getData().getArticle_img_url());
                            String articleContent = wxArticleSpiderResult.getData().getArticle_content();

                            //20191227 hyl
                            articleContent = articleContent.replaceFirst("visibility: hidden;", "max-width: 100%;");
                            articleInfo.setArticleContent(articleContent);

                            articleInfo.setUserId(userInfo.getUserId());
                            articleInfo.setArticleSource(2);
                            articleInfo.setArticleStatus(1);
                            articleInfo.setSpiderProcessStatus(1);
                            articleInfo.setArticleVersionNum(2);
                            articleInfo.setCreateTime(DateUtil.getCurDate());
                            articleInfoService.addWechatArticleInfo(articleInfo);
                        }

                    }

                    //文章图文消息推送
                    WxMpKefuMessage.WxArticle wxArticle = new WxMpKefuMessage.WxArticle();
                    wxArticle.setTitle(articleInfo.getArticleTitle());
                    //wxArticle.setDescription(articleInfo.getArticleDesc()); //屏蔽于 20200504
                    wxArticle.setDescription("");
                    wxArticle.setPicUrl(articleInfo.getArticleImgUrl()+"?"+SysConstant.OSS_PAR_80_80);

                    //拼接链接地址
                    String accessUrl = platformSysInfoConfig.getArticleDetailUrl() + articleInfo.getId();

                    wxArticle.setUrl(accessUrl);
                    WxMpKefuMessage testMsg = WxMpKefuMessage.NEWS().addArticle(wxArticle).toUser(wxMessage.getFromUser()).build();
                    try {
                        weixinService.getKefuService().sendKefuMessage(testMsg);
                    } catch (WxErrorException e) {
                        keyWrodInfo.setReplyStatus(2);
                        keyWrodInfo.setErrMsg(e.getMessage());
                    }

                } else {

                    String errorRespKefuMsg = "上传失败，提示：文章中含有非法关键字。";
                    if (resutCode == 2) {
                        errorRespKefuMsg = "上传失败，提示：文章内容过短。";
                    } else if (resutCode == 3) {
                        errorRespKefuMsg = "上传失败，提示：文章内容过短。";
                    } else if (resutCode == 4) {
                        errorRespKefuMsg = "文章可能涉嫌违规，正在审核中，换一篇文章试试";
                    }

                    if(userInfo.getPhoneModel().equals(SysConstant.IOS)){
                        errorRespKefuMsg =ToolUtil.handleMsgmenuidByIOS(errorRespKefuMsg);
                    }

                    WxMpKefuMessage errorRespMessage = WxMpKefuMessage.TEXT().toUser(wxMessage.getFromUser()).content(errorRespKefuMsg).build();
                    try {
                        weixinService.getKefuService().sendKefuMessage(errorRespMessage);
                    } catch (WxErrorException e) {
                        keyWrodInfo.setReplyStatus(2);
                        keyWrodInfo.setErrMsg(e.getMessage());
                    }

                }

            }
            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
            return null;
        }

        //多个客服二维码 循环回复
        if (StringUtils.isNotBlank(userSendContent) &&
                (
                        userSendContent.equals("6") ||
                                userSendContent.contains("客服") ||
                                userSendContent.contains("什么作用") ||
                                userSendContent.contains("什么意义") ||
                                userSendContent.contains("为什么") ||
                                userSendContent.contains("该怎么") ||
                                userSendContent.contains("干什麼") ||
                                userSendContent.contains("干什么") ||
                                userSendContent.contains("做什么") ||
                                userSendContent.contains("怎么样") ||
                                userSendContent.contains("问问") ||
                                userSendContent.contains("问一下") ||
                                userSendContent.contains("请问") ||
                                userSendContent.contains("在么") ||
                                userSendContent.contains("在吗") ||
                                userSendContent.contains("看不了") ||
                                userSendContent.contains("用不了") ||
                                userSendContent.contains("不会用") ||
                                userSendContent.contains("怎么用") ||
                                userSendContent.contains("点不了") ||
                                userSendContent.contains("打不开") ||
                                userSendContent.contains("什么意思") ||
                                userSendContent.contains("什麼意思") ||
                                userSendContent.contains("是什么") ||
                                userSendContent.contains("怎么打开") ||
                                userSendContent.contains("怎么使用") ||
                                userSendContent.contains("啥情况") ||
                                userSendContent.contains("看不见") ||
                                userSendContent.contains("看不了") ||
                                userSendContent.contains("看不到") ||
                                userSendContent.contains("不明白") ||
                                userSendContent.contains("去哪里") ||
                                userSendContent.contains("在哪里") ||
                                userSendContent.contains("什么生意") ||
                                userSendContent.contains("怎么合作") ||
                                userSendContent.contains("怎么回事") ||
                                userSendContent.contains("啥意思") ||
                                userSendContent.contains("不会发") ||
                                userSendContent.contains("我不会") ||
                                userSendContent.contains("怎么看") ||
                                userSendContent.contains("啥情况") ||
                                userSendContent.contains("不明白") ||
                                userSendContent.contains("没有明白") ||
                                userSendContent.contains("不懂") ||
                                userSendContent.contains("人工服务") ||
                                userSendContent.contains("不会弄") ||
                                userSendContent.contains("靠谱吗") ||
                                userSendContent.contains("怎么修改") ||
                                userSendContent.contains("怎么做") ||
                                userSendContent.contains("什么鬼") ||
                                userSendContent.contains("什么玩意") ||
                                userSendContent.contains("不能互动") ||
                                userSendContent.contains("教我") ||
                                userSendContent.contains("文章打不开") ||
                                userSendContent.contains("能挣钱吗") ||
                                userSendContent.contains("能赚钱吗") ||
                                userSendContent.contains("什么原因") ||
                                userSendContent.contains("怎么操作")
                )
        ) {

            WxMpKefuMessage message = WxMpKefuMessage.TEXT().toUser(wxMessage.getFromUser()).content("添加客服微信解答您的疑惑\uD83D\uDCAC").build();
            weixinService.getKefuService().sendKefuMessage(message);

            /** 20201222 ljt start*/
            try {
                // 异步推送客服二维码
                menuHandler.generalKeFuQrCodePushMsg(wxMessage.getFromUser(), weixinService, platformSysInfoConfig);
            } catch (Exception e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }

            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
            return null;
            /** 20201222 ljt end*/

        }

        //引流伙伴
        if (StringUtils.isNotBlank(userSendContent) && userSendContent.contains("引流伙伴")) {

            WxMpKefuMessage message = WxMpKefuMessage.TEXT().toUser(wxMessage.getFromUser()).content("\uD83D\uDC8E 推广必备！扫码进入\n\n\uD83D\uDC47 \uD83D\uDC47 \uD83D\uDC47").build();
            weixinService.getKefuService().sendKefuMessage(message);
            try {
                String clickSendImg = platformSysInfoConfig.getWxShareImgPath() + "hexy_code.jpg";
                menuHandler.mySendKefuImg(wxMessage, weixinService, clickSendImg, 0);
            } catch (Exception e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }

            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
            return null;

        }


        if (StringUtils.isNotBlank(userSendContent) && userSendContent.trim().equals("86")) {//日报退订 hyl 20200430
            WxNotifyMsgSetInfo wxNotifyMsgSetInfo = new WxNotifyMsgSetInfo();
            wxNotifyMsgSetInfo.setUserId(userInfo.getUserId());
            wxNotifyMsgSetInfo.setDailyDataReportAcceptStatus(0);
            int i = userInfoService.recordUserNotifySetInfo(wxNotifyMsgSetInfo);
            if (i == 1) {
                try {
                    rewMsg = new TextBuilder().build("退订成功", wxMessage, weixinService);
                } catch (Exception e) {
                    keyWrodInfo.setReplyStatus(2);
                    keyWrodInfo.setErrMsg(e.getMessage());
                }

                keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
                return rewMsg;
            }
            return null;
        }

        if (StringUtils.isNotBlank(userSendContent) && userSendContent.trim().equals("81")) {//人脉广场退订 hyl 20200430
            WxNotifyMsgSetInfo wxNotifyMsgSetInfo = new WxNotifyMsgSetInfo();
            wxNotifyMsgSetInfo.setUserId(userInfo.getUserId());
            wxNotifyMsgSetInfo.setConnectionMsgStatus(0);
            int i = userInfoService.recordUserNotifySetInfo(wxNotifyMsgSetInfo);
            if (i == 1) {
                try {
                    rewMsg = new TextBuilder().build("退订成功", wxMessage, weixinService);
                } catch (Exception e) {
                    keyWrodInfo.setReplyStatus(2);
                    keyWrodInfo.setErrMsg(e.getMessage());
                }

                keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
                return rewMsg;
            }
            return null;
        }

        //领取阿里课程
        if (StringUtils.isNotBlank(userSendContent) && userSendContent.contains("领课程")) {

            String msg = SysConstant.PUSH_LQALKC.replace(SysConstant.frontDomain, platformSysInfoConfig.getFrontDomain());

            if(userInfo.getPhoneModel().equals(SysConstant.IOS)){
                msg =ToolUtil.handleMsgmenuidByIOS(msg);
            }

            WxMpKefuMessage message = WxMpKefuMessage.TEXT().toUser(wxMessage.getFromUser()).content(msg).build();
            weixinService.getKefuService().sendKefuMessage(message);

            String clickSendImg = wxShareImgPath + "lqkc.png";
            File resultImg = new File(clickSendImg);

            WxMediaUploadResult wxMediaUploadResult = null;
            try {
                wxMediaUploadResult = weixinService.getMaterialService().mediaUpload(WxConsts.MediaFileType.IMAGE, resultImg);
                String mediaId = wxMediaUploadResult.getMediaId();

                if (StringUtils.isNotBlank(mediaId)) {

                    WxMpKefuMessage messageTwo = WxMpKefuMessage.IMAGE().toUser(wxMessage.getFromUser()).mediaId(mediaId).build();
                    weixinService.getKefuService().sendKefuMessage(messageTwo);

                }
            } catch (WxErrorException e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }
            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
            return null;

        }

        if (StringUtils.isNotBlank(userSendContent) && (userSendContent.trim().equals("更多爆文"))) {//推文章库 hyl 20200430
            try {
                String msg = SysConstant.ARTICLE_PUSH_MSG.replace(SysConstant.frontDomain, platformSysInfoConfig.getFrontDomain());
                if(userInfo.getPhoneModel().equals(SysConstant.IOS)){
                    msg =ToolUtil.handleMsgmenuidByIOS(msg);
                }
                rewMsg = new TextBuilder().build(msg, wxMessage, weixinService);

                //文章图文消息推送
//                WxMpKefuMessage.WxArticle wxArticle = new WxMpKefuMessage.WxArticle();
//                wxArticle.setTitle("你的个人专属微站、海量文章视频知识库！");
//                wxArticle.setDescription("每一篇分享到朋友圈的文章视频都可以带上你的名片宣传");
//                wxArticle.setPicUrl("https://zktuistatic.oss-cn-shenzhen.aliyuncs.com/wxTouXiang/grwz.png");
//
//                wxArticle.setUrl(sysGzh.getRealmResource()+"listTxp.html");
//                WxMpKefuMessage testMsg = WxMpKefuMessage.NEWS().addArticle(wxArticle).toUser(wxMessage.getFromUser()).build();
//
//                weixinService.getKefuService().sendKefuMessage(testMsg);

            } catch (Exception e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }

            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
            return rewMsg;
        }

        if (StringUtils.isNotBlank(userSendContent) && userSendContent.trim().equals("更多视频")) {//推视频库 hyl 20200521
            try {
                String msg = SysConstant.VIDEO_PUSH_MSG.replace(SysConstant.frontDomain, platformSysInfoConfig.getFrontDomain());
                if(userInfo.getPhoneModel().equals(SysConstant.IOS)){
                    msg =ToolUtil.handleMsgmenuidByIOS(msg);
                }
                rewMsg = new TextBuilder().build(msg, wxMessage, weixinService);
            } catch (Exception e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }

            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
            return rewMsg;
        }

        if (StringUtils.isNotBlank(userSendContent) && (userSendContent.trim().equals("邀请有奖") || userSendContent.trim().equals("推广赚钱"))) {//推邀请有奖hyl 20200521
            try {
                String content = SysConstant.CLICK_PROMOTE_MENU_PUSH_MSG2;
                if (userSendContent.trim().equals("推广赚钱")) {
                    content = SysConstant.CLICK_PROMOTE_MENU_PUSH_MSG;
                }

                content = content.replace(SysConstant.frontDomain, platformSysInfoConfig.getFrontDomain());

                if(userInfo.getPhoneModel().equals(SysConstant.IOS)){
                    content =ToolUtil.handleMsgmenuidByIOS(content);
                }

                WxMpKefuMessage message = WxMpKefuMessage.TEXT().toUser(wxMessage.getFromUser()).content(content).build();
                weixinService.getKefuService().sendKefuMessage(message);

                WxMpQrCodeTicket ticket = weixinService.getQrcodeService().qrCodeCreateTmpTicket(userInfo.getUserId(), 2592000);
                File qrCodePictureFile = weixinService.getQrcodeService().qrCodePicture(ticket);

                //商务合作链接
//            WxMpKefuMessage busMessage = WxMpKefuMessage.TEXT().toUser(toUser).content(SysConstant.WX_USER_BUS_COOP_PUSH_MSG).build();
//            weixinService.getKefuService().sendKefuMessage(busMessage);

                //下载用户头像
                String avatarName = UUID.randomUUID().toString() + ".jpg";
                ToolUtil.downloadAvatarPic(userInfo.getAvatarUrl(), userInfo.getUserId(), avatarName);

                String avatarPath = SysConstant.WX_AVATAR_DOWNLOAD_PATH + userInfo.getUserId() + "/" + avatarName;

                String qrCodePath = qrCodePictureFile.getAbsolutePath();

                String validTime = "二维码有效期至" + DateUtil.getFormatDate("yyyy年MM月dd日", DateTime.now().plusDays(30));

                File resultImg = SharedImageUtils.generateSharedImage(avatarPath, qrCodePath, userInfo.getNickName(), validTime, wxShareImgPath, springProfilesActive);

                WxMediaUploadResult wxMediaUploadResult = weixinService.getMaterialService().mediaUpload(WxConsts.MediaFileType.IMAGE, resultImg);

                String mediaId = wxMediaUploadResult.getMediaId();

                rewMsg = new ImageBuilder().build(mediaId, wxMessage, weixinService);

            } catch (WxErrorException e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            } catch (Exception e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }
            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
            return rewMsg;
        }

        /**
         * 牛年头像制作
         */
        if (StringUtils.isNotBlank(userSendContent) && (userSendContent.trim().contains("国庆") ||
                userSendContent.trim().contains("头像")
        )) {

            // 发链接
            menuHandler.setMostNationalDay(wxMessage, weixinService, platformSysInfoConfig);

            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
            return rewMsg;
        }

        /**
         * 国庆头像制作71
         */
//        if (StringUtils.isNotBlank(userSendContent) && (userSendContent.trim().equals("71"))) {
//
//            // 发链接
//            String kefuMsg_0 = "<a href=\"" + platformSysInfoConfig.getHeadSculptureMenuUrl() + "\">✨领取您的国庆头像>></a>";
//            menuHandler.mySendKefuMessage(wxMessage, weixinService, kefuMsg_0, 0);
//
//
//            //int vipStatus = Optional.ofNullable(userInfoService.getUserVipStatus(userInfo.getUserId())).orElse(0);
//
//            String kefuMsg = "[色][色]抢先体验新功能：\n\n" +
//                    "\uD83D\uDC6B<a href=\"weixin://bizmsgmenu?msgmenucontent=团队&msgmenuid=+++\">创建团队共享素材</a>\n\n" +
//                    "\uD83C\uDDE8\uD83C\uDDF3<a href=\"weixin://bizmsgmenu?msgmenucontent=素材&msgmenuid=+++\">中秋国庆发圈素材</a>";
//
//            //if (vipStatus == 0) {
//            kefuMsg = kefuMsg + "\n\n\uD83C\uDF81<a href='" + platformSysInfoConfig.getOpenMemberMenuUrl() + "?mt=1'>国庆优惠价，会员买一送一，点这里参与 >></a>";
//            //}
//
//            menuHandler.mySendKefuMessage(wxMessage, weixinService, kefuMsg, 1000);
//
//            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
//            return rewMsg;
//        }

        //20200521 yl start

        if (StringUtils.isNotBlank(userSendContent) && (userSendContent.trim().equals("奖励金"))) {
            try {
                String msg = SysConstant.COMMISSION_PUSH_MSG.replace(SysConstant.frontDomain, platformSysInfoConfig.getFrontDomain());
                if(userInfo.getPhoneModel().equals(SysConstant.IOS)){
                    msg =ToolUtil.handleMsgmenuidByIOS(msg);
                }
                rewMsg = new TextBuilder().build(msg, wxMessage, weixinService);
            } catch (Exception e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }

            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
            return rewMsg;
        }

        if (StringUtils.isNotBlank(userSendContent) && (
                userSendContent.trim().equals("会员有什么好处") ||
                        userSendContent.contains("免费") ||
                        userSendContent.contains("会员") ||
                        userSendContent.contains("开通") ||
                        userSendContent.contains("收费") ||
                        userSendContent.contains("交钱") ||
                        userSendContent.contains("vip") ||
                        userSendContent.contains("成交") ||
                        userSendContent.contains("怎么收费") ||
                        userSendContent.contains("如何购买") ||
                        userSendContent.contains("多少钱") ||
                        userSendContent.contains("怎么收费")
        )) {
            try {
                String msg = SysConstant.PUSH_MEMBER_BENEFITS.replace(SysConstant.frontDomain, platformSysInfoConfig.getFrontDomain());
                if(userInfo.getPhoneModel().equals(SysConstant.IOS)){
                    msg =ToolUtil.handleMsgmenuidByIOS(msg);
                }
                rewMsg = new TextBuilder().build(msg, wxMessage, weixinService);
            } catch (Exception e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }

            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
            return rewMsg;
        }

        if (StringUtils.isNotBlank(userSendContent) && (userSendContent.trim().equals("新手教程"))) {
            try {
                String msg = SysConstant.HELD_PUSH_MSG.replace(SysConstant.frontDomain, platformSysInfoConfig.getFrontDomain());
                if(userInfo.getPhoneModel().equals(SysConstant.IOS)){
                    msg =ToolUtil.handleMsgmenuidByIOS(msg);
                }
                rewMsg = new TextBuilder().build(msg, wxMessage, weixinService);
            } catch (Exception e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }

            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
            return rewMsg;
        }

        if (StringUtils.isNotBlank(userSendContent) && (userSendContent.trim().equals("早安") || userSendContent.equals("7"))) {
            try {
                Map<String, String> headMap = Maps.newHashMap();
                headMap.put("userId", userInfo.getUserId().toString());
                headMap.put("profile", springProfilesActive);
                String finalReqUrl = platformSysInfoConfig.getTaskUrl() + "callFirstTime";
                HttpClientUtils.sendPost(finalReqUrl, headMap, Maps.newHashMap());
            } catch (Exception e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }

            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
            return null;
        }

        if (StringUtils.isNotBlank(userSendContent) && (userSendContent.trim().equals("打卡") || userSendContent.trim().equals("晚安"))) {

            Calendar rightNow = Calendar.getInstance();
            int hour = rightNow.get(Calendar.HOUR_OF_DAY);

            String anTxt = "早安☀";
            if (hour > 16) {
                anTxt = "晚安\uD83C\uDF19";
            }

            String clockTimeStr = DateUtil.getFormatDate("yyyy-MM-dd", DateUtil.getCurDate());
            int clockStatus = Optional.ofNullable(userPunchClockInfoService.queryUserSpecialDayPunchClockStatus(userInfo.getUserId(), clockTimeStr)).orElse(0);
            PunchClockArticleInfo punchClockArticleInfo = userPunchClockInfoService.getUserPunchClockArticleInfo();
            int clockDays = userPunchClockInfoService.getUserClockDays(userInfo.getUserId());

            if (clockStatus == 0) { //20200229 hyl，用户当天没打 才加1
                clockDays = clockDays + 1;
            }

            //文章图文消息推送
            WxMpKefuMessage.WxArticle wxArticle = new WxMpKefuMessage.WxArticle();
            wxArticle.setTitle("【" + anTxt + "第" + clockDays + "天】" + platformSysInfoConfig.getSysGzh().getGzhName() + ":" + punchClockArticleInfo.getClockArticleTitle());
            wxArticle.setDescription(punchClockArticleInfo.getClockArticleContent());
            wxArticle.setPicUrl(punchClockArticleInfo.getClockArticleThumbnailUrl()+"?"+SysConstant.OSS_PAR_80_80);

            wxArticle.setUrl(platformSysInfoConfig.getClockMenuUrl());
            WxMpKefuMessage testMsg = WxMpKefuMessage.NEWS().addArticle(wxArticle).toUser(wxMessage.getFromUser()).build();

            weixinService.getKefuService().sendKefuMessage(testMsg);

            menuHandler.mySendKefuMessage(wxMessage, weixinService,
                    "\uD83D\uDC49<a href=\"" + platformSysInfoConfig.getFrontDomain() + "pages/article/editBrands.html\">设置你的品牌，接收精准文章</a>", 2000);

            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
            return null;
        }

//        if (StringUtils.isNotBlank(userSendContent) && (userSendContent.trim().equals("晚安"))) {
//            try {
//                rewMsg = new TextBuilder().build("\uD83D\uDC49<a href=\"" + platformSysInfoConfig.getClockMenuUrl() + "\">点击领取" + userSendContent.trim() + "心语</a>", wxMessage, weixinService);
//            } catch (Exception e) {
//                keyWrodInfo.setReplyStatus(2);
//                keyWrodInfo.setErrMsg(e.getMessage());
//            }
//
//            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
//            return rewMsg;
//        }

        if (StringUtils.isNotBlank(userSendContent) && (userSendContent.trim().equals("获取正能量文章"))) {
            try {
                Map<String, String> headMap = Maps.newHashMap();
                headMap.put("userId", userInfo.getUserId().toString());
                headMap.put("profile", springProfilesActive);
                String finalReqUrl = platformSysInfoConfig.getTaskUrl() + "pushPositiveEnergy";
                HttpClientUtils.sendPost(finalReqUrl, headMap, Maps.newHashMap());
            } catch (Exception e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }

            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
            return null;
        }

        // 获取行业文章
        if (StringUtils.isNotBlank(userSendContent) && (userSendContent.trim().contains("|"))) {
            String articleTypeId = userSendContent.substring(userSendContent.indexOf("|") + 1).trim();
            try {
                Map<String, String> headMap = Maps.newHashMap();
                headMap.put("userId", userInfo.getUserId().toString());
                headMap.put("profile", springProfilesActive);
                headMap.put("articleTypeId", articleTypeId);
                String finalReqUrl = platformSysInfoConfig.getTaskUrl() + "pushUserArticleType";
                HttpClientUtils.sendPost(finalReqUrl, headMap, Maps.newHashMap());
            } catch (Exception e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }

            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
            return null;
        }

        if (StringUtils.isNotBlank(userSendContent) && (userSendContent.trim().contains("@视频:") || userSendContent.trim().contains("@文章:"))) {
            try {
                String[] s = userSendContent.trim().split(":");
                String enArticleId = "";
                if (s != null && s.length > 1) {
                    enArticleId = s[1];
                }

                Map<String, String> headMap = Maps.newHashMap();
                headMap.put("userId", userInfo.getUserId().toString());
                headMap.put("profile", springProfilesActive);
                headMap.put("enArticleId", enArticleId);
                String finalReqUrl = platformSysInfoConfig.getTaskUrl() + "pushArticleByEnId";
                HttpClientUtils.sendPost(finalReqUrl, headMap, Maps.newHashMap());
            } catch (Exception e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }

            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
            return null;
        }

        if (StringUtils.isNotBlank(userSendContent) && (
                userSendContent.trim().equals("XSJQ")
                        || userSendContent.trim().equals("JTJY")
        )) {
            try {
                Map<String, String> headMap = Maps.newHashMap();
                headMap.put("userId", userInfo.getUserId().toString());
                headMap.put("profile", springProfilesActive);
                if (userSendContent.trim().equals("XSJQ")) {
                    headMap.put("brandId", "14212");
                } else if (userSendContent.trim().equals("JTJY")) {
                    headMap.put("brandId", "11845");
                }
                String finalReqUrl = platformSysInfoConfig.getTaskUrl() + "pushBrandArticle";
                HttpClientUtils.sendPost(finalReqUrl, headMap, Maps.newHashMap());
            } catch (Exception e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }

            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
            return null;
        }


        if (StringUtils.isNotBlank(userSendContent) && (userSendContent.trim().equals("开单学堂"))) {
            try {
                Map<String, String> headMap = Maps.newHashMap();
                headMap.put("userId", userInfo.getUserId().toString());
                headMap.put("profile", springProfilesActive);
                String finalReqUrl = platformSysInfoConfig.getTaskUrl() + "push_KDXT";
                HttpClientUtils.sendPost(finalReqUrl, headMap, Maps.newHashMap());
            } catch (Exception e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }

            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
            return null;
        }

        if (StringUtils.isNotBlank(userSendContent) && (userSendContent.trim().equals("活动详情"))) {
            try {
                String msg = SysConstant.CLICK_HDXQ_PUSH_MSG.replace(SysConstant.frontDomain, platformSysInfoConfig.getFrontDomain());
                if(userInfo.getPhoneModel().equals(SysConstant.IOS)){
                    msg =ToolUtil.handleMsgmenuidByIOS(msg);
                }
                rewMsg = new TextBuilder().build(msg, wxMessage, weixinService);
            } catch (Exception e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }

            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
            return rewMsg;
        }

        if (StringUtils.isNotBlank(userSendContent) && (userSendContent.trim().equals("成为合伙人"))) {
            try {
                String msg = SysConstant.COOPERATION_PUSH_MSG.replace("[cooperationUrl]", platformSysInfoConfig.getCooperationUrl());
                if(userInfo.getPhoneModel().equals(SysConstant.IOS)){
                    msg =ToolUtil.handleMsgmenuidByIOS(msg);
                }
                rewMsg = new TextBuilder().build(msg, wxMessage, weixinService);
            } catch (Exception e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }

            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
            return rewMsg;
        }

        if (StringUtils.isNotBlank(userSendContent) && (userSendContent.trim().equals("设置推送频率"))) {
            try {
                String msg = SysConstant.SET_PUSH_MSG.replace(SysConstant.frontDomain, platformSysInfoConfig.getFrontDomain());
                if(userInfo.getPhoneModel().equals(SysConstant.IOS)){
                    msg =ToolUtil.handleMsgmenuidByIOS(msg);
                }
                rewMsg = new TextBuilder().build(msg, wxMessage, weixinService);
            } catch (Exception e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }

            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
            return rewMsg;
        }

        if (StringUtils.isNotBlank(userSendContent) && (userSendContent.trim().equals("营销课程"))) {
            try {
                returnKF(weixinService, wxMessage.getFromUser(), platformSysInfoConfig);
                String msg = SysConstant.YXKC_PUSH_MSG;
                if(userInfo.getPhoneModel().equals(SysConstant.IOS)){
                    msg =ToolUtil.handleMsgmenuidByIOS(msg);
                }
                rewMsg = new TextBuilder().build(msg, wxMessage, weixinService);
            } catch (Exception e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }

            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
            return rewMsg;
        }

        if (StringUtils.isNotBlank(userSendContent) && (userSendContent.trim().equals("领取优惠") || userSendContent.trim().equals("8"))) {

            try {

                // 国庆先发头像链接
//                menuHandler.setMostNationalDay(wxMessage, weixinService, platformSysInfoConfig);
//                Thread.sleep(10000);

                Map<String, String> headMap = Maps.newHashMap();
                headMap.put("userId", userInfo.getUserId().toString());
                headMap.put("profile", springProfilesActive);
                String finalReqUrl = platformSysInfoConfig.getTaskUrl() + "testCoupon";
                HttpClientUtils.sendPost(finalReqUrl, headMap, Maps.newHashMap());
            } catch (Exception e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }

            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
            return rewMsg;
        }

        //7,送7天免费会员
//        if (StringUtils.isNotBlank(userSendContent) ) {
//
//            try {
//                String clickSendImg=platformSysInfoConfig.getWxShareImgPath()+"vip7.jpg";
//                menuHandler.mySendKefuImg(wxMessage, weixinService,clickSendImg,0);
//            } catch (Exception e) {
//                keyWrodInfo.setReplyStatus(2);
//                keyWrodInfo.setErrMsg(e.getMessage());
//            }
//
//            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
//            return null;
//
//        }

        if (StringUtils.isNotBlank(userSendContent) && userSendContent.trim().equals("TTMsg")) {

            try {
                Map<String, String> headMap = Maps.newHashMap();
                headMap.put("userId", userInfo.getUserId().toString());
                headMap.put("profile", springProfilesActive);
                String finalReqUrl = platformSysInfoConfig.getTaskUrl() + "getTemplateMessage";
                HttpClientUtils.sendPost(finalReqUrl, headMap, Maps.newHashMap());
            } catch (Exception e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }

            WxMpTemplateMessage templateMessage1 = WxMpTemplateMessage.builder()
                    // 接收者openid
                    .toUser(fromUserOpenId)
                    .templateId(platformSysInfoConfig.getSysGzh().getBuyVipMessagePushTempId())
                    .url(platformSysInfoConfig.getArticleListMenuUrl())
                    .build();
            String firstMsg = userInfo.getNickName() + "您的会员账号已经开通，尽情使用吧！\n\n";
            String remarkMsg = "如有疑问，可回复【客服】来了解详情。\n\n";

            templateMessage1.addData(new WxMpTemplateData("first", firstMsg, "#FF00FF"))
                    .addData(new WxMpTemplateData("keyword1", userInfo.getNickName(), "#A9A9A9"))
                    .addData(new WxMpTemplateData("keyword2", "2020-05-12", "#A9A9A9"))
                    .addData(new WxMpTemplateData("keyword3", "2021-05-12", "#A9A9A9"))
                    .addData(new WxMpTemplateData("remark", remarkMsg, "#0000FF"));

            WxMpTemplateMessage templateMessage2 = WxMpTemplateMessage.builder()
                    // 接收者openid
                    .toUser(fromUserOpenId)
                    // 模板id
//                    .templateId(pushBuyVipTempID)
                    .templateId(platformSysInfoConfig.getSysGzh().getPushBuyVipTempId())
                    // 模板跳转链接
//                    .url(platformSysInfoConfig.getFrontDomain()+ "/pages/setting/commission.html")
                    .url(platformSysInfoConfig.getFrontDomain() + "/pages/setting/commission.html")
                    .build();
            String firstMsg1 = "恭喜您，一笔佣金结算成功!\n\n";
            String remarkMsg1 = "点击查看佣金详细明细。\n\n";

            // 添加模板数据
            templateMessage2.addData(new WxMpTemplateData("first", firstMsg1, "#FF00FF"))
                    .addData(new WxMpTemplateData("keyword1", userInfo.getNickName(), "#A9A9A9"))
                    .addData(new WxMpTemplateData("keyword2", DateUtil.getFormatDate(null, DateUtil.getCurDate()), "#A9A9A9"))
                    .addData(new WxMpTemplateData("keyword3", "佣金分成", "#A9A9A9"))
                    .addData(new WxMpTemplateData("keyword4", "消费提成", "#A9A9A9"))
                    .addData(new WxMpTemplateData("keyword5", String.valueOf(9999.99), "#A9A9A9"))
                    .addData(new WxMpTemplateData("remark", remarkMsg1, "#0000FF"));


            WxMpTemplateMessage templateMessage3 = WxMpTemplateMessage.builder()
                    // 接收者openid
                    .toUser(fromUserOpenId)
                    // 模板id
                    //.templateId(applyMessagePushTempID)
                    .templateId(platformSysInfoConfig.getSysGzh().getApplyMessagePushTempId())
                    // 模板跳转链接
//                    .url(platformSysInfoConfig.getConnectionPlazaUrl())  //启用于 20210504
                    .url(platformSysInfoConfig.getConnectionPlazaUrl() + "?return=0")//跳到 我的人脉
                    .build();
            String firstMsg3 = "您好，有人加您为好友哦⭕";
            String remarkMsg3 = "回复数字【 2 】进入人脉广场";

            // 添加模板数据
            templateMessage3.addData(new WxMpTemplateData("first", firstMsg3, "#FF00FF"))
                    .addData(new WxMpTemplateData("keyword1", userInfo.getNickName(), "#A9A9A9"))
                    .addData(new WxMpTemplateData("keyword2", "添加好友", "#A9A9A9"))
                    .addData(new WxMpTemplateData("keyword3", DateUtil.getFormatDate(null, new Date()), "#A9A9A9"))
                    .addData(new WxMpTemplateData("remark", remarkMsg3, "#FF0000"));


            // 发送模板消息接口
            WxMpTemplateMessage templateMessage4 = WxMpTemplateMessage.builder()
                    // 接收者openid
                    .toUser(fromUserOpenId)
                    // 模板id
                    //.templateId(passesMessagePushTempID)
                    .templateId(platformSysInfoConfig.getSysGzh().getPassesMessagePushTempId())
                    // 模板跳转链接
                    //.url(platformSysInfoConfig.getConnectionPlazaUrl())
                    .url(platformSysInfoConfig.getConnectionPlazaUrl() + "?return=0")//跳到 我的人脉
                    .build();
            String firstMsg4 = "您的好友申请已通过⭕";
            String remarkMsg4 = "回复数字【 2 】进入人脉广场";

            // 添加模板数据
            templateMessage4.addData(new WxMpTemplateData("first", firstMsg4, "#FF00FF"))
                    .addData(new WxMpTemplateData("keyword1", userInfo.getNickName(), "#A9A9A9"))
                    .addData(new WxMpTemplateData("keyword2", userInfo.getNickName() + "同意了您的好友请求", "#A9A9A9"))
                    .addData(new WxMpTemplateData("remark", remarkMsg4, "#FF0000"));


            List<UserBrandCombinedInfo> ubList = userBrandInfoService.getUserBrandInfo(userInfo.getUserId());
            String toUserBrand = "";
            if (ubList != null && ubList.size() > 0) {
                toUserBrand = ubList.get(0).getBrandName();
            }

            // 发送模板消息接口
            WxMpTemplateMessage templateMessage5 = WxMpTemplateMessage.builder()
                    // 接收者openid
                    .toUser(fromUserOpenId)
                    .templateId(platformSysInfoConfig.getSysGzh().getApplyMessagePushTempId())
                    // 模板跳转链接
                    .url(platformSysInfoConfig.getConnectionPlazaUrl() + "?return=0")//跳到 我的人脉
                    .build();
            String firstMsg5 = "⭕ 您有一条新的客户需求待领取：";

            String[] m_arr = {
                    "我想了解【" + toUserBrand + "】，加个微信？\n" +
                            "\n" +
                            "回复数字【 2 】加她聊聊>>\n" +
                            "\n" +
                            "如果给您带来不便，回复81，取消推送消息。",

                    "咨询购买产品\n" +
                            "\n" +
                            "回复数字【 2 】联系她>>\n" +
                            "\n" +
                            "如果给您带来不便，回复81，取消推送消息。"
            };

            int index = (int) (Math.random() * m_arr.length);
            String remarkMsg5 = m_arr[index];

            String telNum = (userInfo.getTelNum() == null ? "***********" : userInfo.getTelNum());
            if (telNum.length() >= 3) {
                telNum = telNum.substring(0, 3) + "********";
            }

            // 添加模板数据
            templateMessage5.addData(new WxMpTemplateData("first", firstMsg5, "#FF00FF"))
                    .addData(new WxMpTemplateData("keyword1", userInfo.getNickName(), "#A9A9A9"))
                    .addData(new WxMpTemplateData("keyword2", telNum, "#A9A9A9"))
                    .addData(new WxMpTemplateData("keyword3", DateUtil.getFormatDate(null, new Date()), "#A9A9A9"))
                    .addData(new WxMpTemplateData("remark", remarkMsg5, "#FF0000"));


            WxMpTemplateMessage templateMessage6 = WxMpTemplateMessage.builder()
                    // 接收者openid
                    .toUser(fromUserOpenId)
                    // 模板id
                    .templateId(platformSysInfoConfig.getSysGzh().getCustomerFollowupTempId())//客户跟进提醒
                    // 模板跳转链接
                    .url(platformSysInfoConfig.getCustomerMenuUrl())
                    .build();

            String firstMsg6 = String.format("有人看了您的文章《%s》", "中华人民共和国");

            String remarkMsg6 = "\uD83D\uDC49回复数字【 1 】看看他/她是谁";

            // 添加模板数据
            templateMessage6.addData(new WxMpTemplateData("first", firstMsg6, "#FF00FF"))
                    .addData(new WxMpTemplateData("keyword1", "-", "#A9A9A9"))
                    .addData(new WxMpTemplateData("keyword2", userInfo.getNickName(), "#A9A9A9"))
                    .addData(new WxMpTemplateData("keyword3", "潜在客户", "#A9A9A9"))
                    .addData(new WxMpTemplateData("remark", remarkMsg6, "#FF0000"));


            String msgId1 = null;
            String msgId2 = null;
            String msgId3 = null;
            String msgId4 = null;
            try {
                // 发送模板消息
                msgId1 = weixinService.getTemplateMsgService().sendTemplateMsg(templateMessage1);
                msgId2 = weixinService.getTemplateMsgService().sendTemplateMsg(templateMessage2);
                msgId3 = weixinService.getTemplateMsgService().sendTemplateMsg(templateMessage3);
                msgId4 = weixinService.getTemplateMsgService().sendTemplateMsg(templateMessage4);
                weixinService.getTemplateMsgService().sendTemplateMsg(templateMessage5);
                weixinService.getTemplateMsgService().sendTemplateMsg(templateMessage6);
            } catch (WxErrorException e) {
                //e.printStackTrace();
            }

            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
            return rewMsg;
        }

        if (StringUtils.isNotBlank(userSendContent) && (userSendContent.trim().equals("查看版本"))) {

            try {
                String msg = "➜ <a href='" + platformSysInfoConfig.getFrontDomain() + "/versions.html'>前端版本</a>\n\n" +
                        "➜ <a href='" + platformSysInfoConfig.getSysGzh().getServerUrl() + "/vtool_versions.html'>接口版本</a>";
                if(userInfo.getPhoneModel().equals(SysConstant.IOS)){
                    msg =ToolUtil.handleMsgmenuidByIOS(msg);
                }
                rewMsg = new TextBuilder().build(msg, wxMessage, weixinService);
            } catch (Exception e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }

            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
            return rewMsg;
        }

        if (StringUtils.isNotBlank(userSendContent) && (userSendContent.trim().equals("工具包"))) {
            try {
                String msg = SysConstant.GJB_PUSH_MSG.replace(SysConstant.frontDomain, platformSysInfoConfig.getFrontDomain());
                if(userInfo.getPhoneModel().equals(SysConstant.IOS)){
                    msg =ToolUtil.handleMsgmenuidByIOS(msg);
                }
                rewMsg = new TextBuilder().build(msg, wxMessage, weixinService);
            } catch (Exception e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }

            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
            return rewMsg;
        }

        if (StringUtils.isNotBlank(userSendContent) && (userSendContent.trim().equals("添加文章"))) {
            try {
                String msg = SysConstant.ADD_ARTICLE_PUSH_MSG.replace(SysConstant.frontDomain, platformSysInfoConfig.getFrontDomain());
                if(userInfo.getPhoneModel().equals(SysConstant.IOS)){
                    msg =ToolUtil.handleMsgmenuidByIOS(msg);
                }
                rewMsg = new TextBuilder().build(msg, wxMessage, weixinService);
            } catch (Exception e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }

            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
            return rewMsg;
        }

        if (StringUtils.isNotBlank(userSendContent) && (userSendContent.trim().equals("订阅明天文章") || userSendContent.trim().equals("5"))) {
            try {
                String msg = "订阅成功！\n\n明天小编将为您继续推送文章哦~~请记得查看哦\uD83D\uDE18";
                if(userInfo.getPhoneModel().equals(SysConstant.IOS)){
                    msg =ToolUtil.handleMsgmenuidByIOS(msg);
                }
                rewMsg = new TextBuilder().build(msg, wxMessage, weixinService);
            } catch (Exception e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }

            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
            return rewMsg;
        }

        if (StringUtils.isNotBlank(userSendContent) && userSendContent.trim().equals("618")) {

            try {
                String msg = "\uD83D\uDC49<a href=\"" + platformSysInfoConfig.getOpenMemberMenuUrl() + "?mt=1&cardBag=1\">立即领取618活动优惠</a>";
                if(userInfo.getPhoneModel().equals(SysConstant.IOS)){
                    msg =ToolUtil.handleMsgmenuidByIOS(msg);
                }
                rewMsg = new TextBuilder().build(msg, wxMessage, weixinService);
            } catch (Exception e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }

            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
            return rewMsg;
        }

        if (StringUtils.isNotBlank(userSendContent) && (userSendContent.trim().equals("缓存"))) {
            try {
                String msg = SysConstant.CLEAN_PUSH_MSG.replace(SysConstant.frontDomain, platformSysInfoConfig.getFrontDomain());
                if(userInfo.getPhoneModel().equals(SysConstant.IOS)){
                    msg =ToolUtil.handleMsgmenuidByIOS(msg);
                }
                rewMsg = new TextBuilder().build(msg, wxMessage, weixinService);
            } catch (Exception e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }

            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
            return rewMsg;
        }

        /*if (StringUtils.isNotBlank(userSendContent) && (userSendContent.trim().equals("人脉广场") || userSendContent.trim().equals("2"))) {
            try {
                String msg = "\uD83D\uDC49<a href=\"" + platformSysInfoConfig.getConnectionPlazaUrl() + "\">点击进入人脉广场</a>";
                if(userInfo.getPhoneModel().equals(SysConstant.IOS)){
                    msg =ToolUtil.handleMsgmenuidByIOS(msg);
                }
                rewMsg = new TextBuilder().build(msg, wxMessage, weixinService);
            } catch (Exception e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }

            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
            return rewMsg;
        }*/

        if (StringUtils.isNotBlank(userSendContent) && userSendContent.trim().equals("2")) {
            WxMpKefuMessage.WxArticle wxArticle = new WxMpKefuMessage.WxArticle();
            wxArticle.setTitle("速看丨教培人线上低成本获客实操手册！");
            wxArticle.setDescription("");
            wxArticle.setPicUrl("https://zktuistatic.oss-cn-shenzhen.aliyuncs.com/wxTouXiang/jp.jpg");
            wxArticle.setUrl("https://mp.weixin.qq.com/s/ui2YKMmHHNkb6ySE23qaOw");
            WxMpKefuMessage testMsg = WxMpKefuMessage.NEWS().addArticle(wxArticle).toUser(wxMessage.getFromUser()).build();

            weixinService.getKefuService().sendKefuMessage(testMsg);

            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
            return null;
        }

        if (StringUtils.isNotBlank(userSendContent) && (userSendContent.trim().equals("团队"))) {
            try {
                String msg = "\uD83D\uDC6B<a href=\"" + platformSysInfoConfig.getFrontDomain() + "/list.html?return=2&v=35#\">点击进入团队功能>>></a>";
                if(userInfo.getPhoneModel().equals(SysConstant.IOS)){
                    msg =ToolUtil.handleMsgmenuidByIOS(msg);
                }
                rewMsg = new TextBuilder().build(msg, wxMessage, weixinService);
            } catch (Exception e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }

            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
            return rewMsg;
        }

        if (StringUtils.isNotBlank(userSendContent) && (userSendContent.trim().equals("快速添加文章与视频"))) {
            try {
                String clickSendImg = platformSysInfoConfig.getWxShareImgPath() + "AddArticleVideo.png";
                menuHandler.mySendKefuImg(wxMessage, weixinService, clickSendImg, 0);
            } catch (Exception e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }

            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
            return rewMsg;
        }

        // create_time 2022-03-04
        if (StringUtils.isNotBlank(userSendContent) && (userSendContent.trim().equals("快速添加文章"))) {
            try {
                String clickSendImg = platformSysInfoConfig.getWxShareImgPath() + "AddArticle.png";
                menuHandler.mySendKefuImg(wxMessage, weixinService, clickSendImg, 0);
            } catch (Exception e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }

            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
            return rewMsg;
        }

        if (StringUtils.isNotBlank(userSendContent) && (userSendContent.trim().equals("素材") || userSendContent.trim().equals("4"))) {
            try {
                /*String msg = "\uD83D\uDC49<a href=\"" + platformSysInfoConfig.getFrontDomain() + "/list.html?tab=material&materialId=33\">点击进入素材库</a>\uD83D\uDC48\n" +
                        "\uD83D\uDC49<a href=\"" + platformSysInfoConfig.getFrontDomain() + "/list.html?tab=material&materialId=33\">点击进入素材库</a>\uD83D\uDC48\n" +
                        "\uD83D\uDC49<a href=\"" + platformSysInfoConfig.getFrontDomain() + "/list.html?tab=material&materialId=33\">点击进入素材库</a>\uD83D\uDC48";*/

                String msg = "\uD83D\uDC49<a href=\"" + platformSysInfoConfig.getFrontDomain() + "/list.html\">点击进入素材库</a>\uD83D\uDC48\n" +
                        "\uD83D\uDC49<a href=\"" + platformSysInfoConfig.getFrontDomain() + "/list.html\">点击进入素材库</a>\uD83D\uDC48\n" +
                        "\uD83D\uDC49<a href=\"" + platformSysInfoConfig.getFrontDomain() + "/list.html\">点击进入素材库</a>\uD83D\uDC48";
                if(userInfo.getPhoneModel().equals(SysConstant.IOS)){
                    msg =ToolUtil.handleMsgmenuidByIOS(msg);
                }
                rewMsg = new TextBuilder().build(msg, wxMessage, weixinService);

                //文章图文消息推送
//                WxMpKefuMessage.WxArticle wxArticle = new WxMpKefuMessage.WxArticle();
//                wxArticle.setTitle("没有好的朋友圈素材？"+platformSysInfoConfig.getSysGzh().getGzhName()+"发圈素材帮到你！");
//                wxArticle.setDescription("给您准备好的发朋友圈内容，节省时间，助你专业推广！");
//                wxArticle.setPicUrl("https://zktuistatic.oss-cn-shenzhen.aliyuncs.com/wxTouXiang/fqsc.png");
//
//                wxArticle.setUrl(platformSysInfoConfig.getFrontDomain() + "/list.html?tab=material&materialId=33");
//                WxMpKefuMessage testMsg = WxMpKefuMessage.NEWS().addArticle(wxArticle).toUser(wxMessage.getFromUser()).build();
//
//                weixinService.getKefuService().sendKefuMessage(testMsg);

            } catch (Exception e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }

            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
            return rewMsg;
        }

        /*if (StringUtils.isNotBlank(userSendContent) && (userSendContent.trim().equals("3") ||
                userSendContent.trim().equals("品牌") ||
                userSendContent.trim().equals("设置品牌") ||
                userSendContent.trim().equals("修改品牌") ||
                userSendContent.trim().equals("编辑品牌") ||
                userSendContent.trim().equals("更新品牌") ||
                userSendContent.trim().equals("改品牌"))) {
            try {
                String msg = "\uD83D\uDC49<a href=\"" + platformSysInfoConfig.getFrontDomain() + "/pages/article/editBrands.html\">点击设置品牌</a>";
                if(userInfo.getPhoneModel().equals(SysConstant.IOS)){
                    msg =ToolUtil.handleMsgmenuidByIOS(msg);
                }
                rewMsg = new TextBuilder().build(msg, wxMessage, weixinService);
            } catch (Exception e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }

            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
            return rewMsg;
        }*/

        if (StringUtils.isNotBlank(userSendContent) && (userSendContent.trim().equals("设置我的行业"))) {
            try {
                String msg = "\uD83D\uDC49<a href=\"" + platformSysInfoConfig.getFrontDomain() + "/list.html?act=1\">点击设置行业</a>";
                if(userInfo.getPhoneModel().equals(SysConstant.IOS)){
                    msg =ToolUtil.handleMsgmenuidByIOS(msg);
                }
                rewMsg = new TextBuilder().build(msg, wxMessage, weixinService);
            } catch (Exception e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }

            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
            return rewMsg;
        }

        if (StringUtils.isNotBlank(userSendContent) && userSendContent.trim().equals("品牌海报")) {
            try {
                String msg = "\uD83D\uDC49<a href=\"" + platformSysInfoConfig.getFrontDomain() + "/pages/setting/setup.html\">点击多品牌专属海报</a>";
                if(userInfo.getPhoneModel().equals(SysConstant.IOS)){
                    msg =ToolUtil.handleMsgmenuidByIOS(msg);
                }
                rewMsg = new TextBuilder().build(msg, wxMessage, weixinService);
            } catch (Exception e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }

            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
            return rewMsg;
        }

        if (StringUtils.isNotBlank(userSendContent) && (userSendContent.trim().equals("t6"))) {

            try {
                Map<String, String> headMap = Maps.newHashMap();
                headMap.put("userId", userInfo.getUserId().toString());
                headMap.put("profile", springProfilesActive);
                String finalReqUrl = platformSysInfoConfig.getTaskUrl() + "testFirstTime";
                HttpClientUtils.sendPost(finalReqUrl, headMap, Maps.newHashMap());
            } catch (Exception e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }

            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
            return null;
        }

        if (StringUtils.isNotBlank(userSendContent) && (userSendContent.trim().equals("t8"))) {
            try {
                Map<String, String> headMap = Maps.newHashMap();
                headMap.put("userId", userInfo.getUserId().toString());
                headMap.put("profile", springProfilesActive);
                String finalReqUrl = platformSysInfoConfig.getTaskUrl() + "testSecondTime";
                HttpClientUtils.sendPost(finalReqUrl, headMap, Maps.newHashMap());
            } catch (Exception e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }

            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
            return null;
        }

        if (StringUtils.isNotBlank(userSendContent) && (userSendContent.trim().equals("t11"))) {
            try {
                Map<String, String> headMap = Maps.newHashMap();
                headMap.put("userId", userInfo.getUserId().toString());
                headMap.put("profile", springProfilesActive);
                String finalReqUrl = platformSysInfoConfig.getTaskUrl() + "testFifthTime";
                HttpClientUtils.sendPost(finalReqUrl, headMap, Maps.newHashMap());
            } catch (Exception e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }

            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
            return null;
        }

        if (StringUtils.isNotBlank(userSendContent) && (userSendContent.trim().equals("t18"))) {
            try {
                Map<String, String> headMap = Maps.newHashMap();
                headMap.put("userId", userInfo.getUserId().toString());
                headMap.put("profile", springProfilesActive);
                String finalReqUrl = platformSysInfoConfig.getTaskUrl() + "testThirdTime";
                HttpClientUtils.sendPost(finalReqUrl, headMap, Maps.newHashMap());
            } catch (Exception e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }

            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
            return null;
        }

        if (StringUtils.isNotBlank(userSendContent) && (userSendContent.trim().equals("t21"))) {
            try {
                Map<String, String> headMap = Maps.newHashMap();
                headMap.put("userId", userInfo.getUserId().toString());
                headMap.put("profile", springProfilesActive);
                String finalReqUrl = platformSysInfoConfig.getTaskUrl() + "testForthTime";
                HttpClientUtils.sendPost(finalReqUrl, headMap, Maps.newHashMap());
            } catch (Exception e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }

            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
            return null;
        }

        if (StringUtils.isNotBlank(userSendContent) && (userSendContent.trim().equals("t20"))) {
            try {
                Map<String, String> headMap = Maps.newHashMap();
                headMap.put("userId", userInfo.getUserId().toString());
                headMap.put("profile", springProfilesActive);
                String finalReqUrl = platformSysInfoConfig.getTaskUrl() + "testSixthTime";
                HttpClientUtils.sendPost(finalReqUrl, headMap, Maps.newHashMap());
            } catch (Exception e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }

            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
            return null;
        }

        if (StringUtils.isNotBlank(userSendContent) && (userSendContent.trim().equals("t17"))) {
            try {
                Map<String, String> headMap = Maps.newHashMap();
                headMap.put("userId", userInfo.getUserId().toString());
                headMap.put("profile", springProfilesActive);
                String finalReqUrl = platformSysInfoConfig.getTaskUrl() + "test1710Time";
                HttpClientUtils.sendPost(finalReqUrl, headMap, Maps.newHashMap());
            } catch (Exception e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }

            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
            return null;
        }

        if (StringUtils.isNotBlank(userSendContent) && (userSendContent.trim().equals("1030")
                || userSendContent.trim().equals("930"))) {
            try {
                Map<String, String> headMap = Maps.newHashMap();
                headMap.put("userId", userInfo.getUserId().toString());
                headMap.put("profile", springProfilesActive);
                String finalReqUrl = platformSysInfoConfig.getTaskUrl() + "test" + userSendContent.trim();
                HttpClientUtils.sendPost(finalReqUrl, headMap, Maps.newHashMap());
            } catch (Exception e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }

            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
            return null;
        }

        //20200521 yl end

        //微信爆单成交术
//        if (StringUtils.isNotBlank(userSendContent) && userSendContent.contains("12")) {
//
//            String clickSendImg = wxShareImgPath + "bdcjs.png";
//            File resultImg = new File(clickSendImg);
//
//            WxMediaUploadResult wxMediaUploadResult = null;
//            try {
//                wxMediaUploadResult = weixinService.getMaterialService().mediaUpload(WxConsts.MediaFileType.IMAGE, resultImg);
//                String mediaId = wxMediaUploadResult.getMediaId();
//
//                if (StringUtils.isNotBlank(mediaId)) {
//
//                    WxMpKefuMessage messageTwo = WxMpKefuMessage.IMAGE().toUser(wxMessage.getFromUser()).mediaId(mediaId).build();
//                    weixinService.getKefuService().sendKefuMessage(messageTwo);
//
//                }
//            } catch (WxErrorException e) {
//                keyWrodInfo.setReplyStatus(2);
//                keyWrodInfo.setErrMsg(e.getMessage());
//            }
//            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
//            return null;
//
//        }

        if (StringUtils.isNotBlank(userSendContent) && userSendContent.contains("8777")) {
            /*fileFeignClient.updateFile("https://mmbiz.qpic.cn/mmbiz_jpg/jL1hNwBkicA1WBkPagOXUibiadpnjAvWGRSkCBmtQW23ibqQrCQJJkEVrY0Qx0aeGHhIAKphJKibd1o32vhX6VRNOicg/640?wx_fmt=jpeg",
                    "testWebSpiderImg/" + DateUtil.getCurDate().getTime() + "/77777.png");*/
            AliyunOssClientUtil.uploadFileByUrl("https://mmbiz.qpic.cn/mmbiz_jpg/jL1hNwBkicA1WBkPagOXUibiadpnjAvWGRSkCBmtQW23ibqQrCQJJkEVrY0Qx0aeGHhIAKphJKibd1o32vhX6VRNOicg/640?wx_fmt=jpeg",
                    "testWebSpiderImg/" + DateUtil.getCurDate().getTime() + "/77777.png");

        }

        //神秘礼品
        if (StringUtils.isNotBlank(userSendContent) && userSendContent.contains("神秘礼品")) {

            try {
                String msg = "[愉快]老师，开通会员都可以领取礼品哦\uD83C\uDF81\n\n" +
                        "\uD83D\uDC49<a href=\"" + platformSysInfoConfig.getOpenMemberMenuUrl() + "\">点我去升级会员>>></a>\n\n" +
                        "[疑问]如果您已经是会员、或者想先咨询了解具体的功能\n\n" +
                        "\uD83D\uDC49<a href=\"weixin://bizmsgmenu?msgmenucontent=客服&msgmenuid=+++\">请点这里[呼叫客服]</a>";

                if (userInfo.getPhoneModel().equals(SysConstant.IOS)) {
                    msg = ToolUtil.handleMsgmenuidByIOS(msg);
                }

                rewMsg = new TextBuilder().build(msg, wxMessage, weixinService);
            } catch (Exception e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }

            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
            return rewMsg;

        }


        if (StringUtils.isNotBlank(userSendContent) && userSendContent.contains("小程序test")) {

            try {
                String msg = "<a data-miniprogram-appid=\"wxfd8301588fd5d875\" data-miniprogram-path=\"/pages/index/index\" href=\"\">小幸早晚安>>></a>";
                if(userInfo.getPhoneModel().equals(SysConstant.IOS)){
                    msg =ToolUtil.handleMsgmenuidByIOS(msg);
                }
                rewMsg = new TextBuilder().build(msg, wxMessage, weixinService);
            } catch (Exception e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }

            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
            return rewMsg;

        }


        if (StringUtils.isNotBlank(userSendContent) && userSendContent.trim().length() <= 30) {

            List<SearchBrandInfo> brandInfoList = brandInfoService.getBrandInfoByBrandName(userSendContent.trim());
            if (brandInfoList != null && brandInfoList.size() > 0) {
                SearchBrandInfo brandInfo = brandInfoList.get(0);

                List<UserBrandCombinedInfo> userBrands = userBrandInfoService.getUserBrandInfo(userInfo.getUserId());

                Integer falg = 0;
                if (userBrands != null) {
                    for (UserBrandCombinedInfo userBrandInfo : userBrands) {
                        if (userBrandInfo.getBrandId().equals(brandInfo.getBrandId())) {
                            falg = 1;
                            break;
                        }
                    }
                }

                String msg = SysConstant.BRAND_PUSH_MSG;
                if (falg.equals(1)) {
                    msg = SysConstant.BRAND_LOOK_PUSH_MSG;
                }
                msg = msg.replace("[BrandName]", brandInfo.getBrandName())
                        .replace("[brandId]", brandInfo.getBrandId().toString())
                        .replace(SysConstant.frontDomain, platformSysInfoConfig.getShareDomainUrl());

                if(userInfo.getPhoneModel().equals(SysConstant.IOS)){
                    msg =ToolUtil.handleMsgmenuidByIOS(msg);
                }

                try {
                    rewMsg = new TextBuilder().build(msg, wxMessage, weixinService);

                } catch (Exception e) {
                    keyWrodInfo.setReplyStatus(2);
                    keyWrodInfo.setErrMsg(e.getMessage());
                }

                keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
                return rewMsg;
            } else {
                try {
                    String msg = SysConstant.KEYWORKS_PUSH_MSG
                            .replace("[keyworks]", userSendContent.trim())
                            .replace(SysConstant.frontDomain, platformSysInfoConfig.getShareDomainUrl());

                    if(userInfo.getPhoneModel().equals(SysConstant.IOS)){
                        msg =ToolUtil.handleMsgmenuidByIOS(msg);
                    }

                    rewMsg = new TextBuilder().build(msg, wxMessage, weixinService);
                } catch (Exception e) {
                    keyWrodInfo.setReplyStatus(2);
                    keyWrodInfo.setErrMsg(e.getMessage());
                }

                keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
                return rewMsg;
            }
        }

        //统一回复
        if (StringUtils.isNotBlank(userSendContent)) {
            try {
                returnKF(weixinService, wxMessage.getFromUser(), platformSysInfoConfig);
            } catch (Exception e) {
                keyWrodInfo.setReplyStatus(2);
                keyWrodInfo.setErrMsg(e.getMessage());
            }

            keywordDetailLogMapper.updateKeyWrodInfo(keyWrodInfo);
            return null;

        }

        return null;
    }

//    @Async
//    public WxMpXmlOutMessage mySendKefuMessage_10sec(WxMpXmlMessage wxMessage, WeixinServiceDL weixinService, UserInfo userInfo, String gzhCode) {
//
//        if (userInfo != null) {
//            int h = 24;
//            KeyWrodInfo keyWrodInfo = keywordDetailLogMapper.getLastKeyWord(gzhCode, userInfo.getUserId());
//
//            if (keyWrodInfo != null) {
//                h = DateUtil.getTimeDiff(3, keyWrodInfo.getCreateTime());
//            }
//
//            Object activeMsgPush = redisCacheUtil.getCacheObject("ACTIVE_10SEC_MSG_PUSH" + userInfo.getUserId());
//
//            if (activeMsgPush == null && h >= 24) {//一个小时内没发过，而且 距离上一次 输入回复已经有24小时
//                try {
//
//                    BrandInfo brandInfo = userBrandInfoService.getUserSelectBrandInfo(userInfo.getUserId());
//
//                    if (brandInfo != null) {
//
//                        String KEFU2_MSG = SysConstant.WX_10SEC.replace("[username]", userInfo.getNickName())
//                                .replace("[brandName]", brandInfo.getBrandName());
//
//                        redisCacheUtil.setCacheObject("ACTIVE_10SEC_MSG_PUSH" + userInfo.getUserId(), 1, 3600);
//
//                        menuHandler.mySendKefuMessage(wxMessage, weixinService, KEFU2_MSG, 10000);
//
//                    }
//                } catch (Exception e) {
//                    e.printStackTrace();
//                }
//            }
//        }
//        return null;
//    }

    /**
     * 20201222 ljt 重写发客服二维码方法
     *
     * @param weixinService
     * @param toUser
     * @param platformSysInfo
     */
    public void returnKF(WeixinServiceDL weixinService, String toUser, PlatformSysInfo platformSysInfo) {
        try {
            //String toUser = wxMessage.getFromUser();
            SysGzh sysGzh = platformSysInfo.getSysGzh();
            String springProfilesActive = sysGzh.getGzhCode();

            // 客服二维码
            String keFuQrCode = "";

            BMessageKefu bMessageKefu = new BMessageKefu();
            bMessageKefu.setGzhCode(springProfilesActive);

            List<BMessageKefu> list = bMessageKefuService.queryAll(bMessageKefu);
            if (CollectionUtils.isNotEmpty(list)) {
                Integer number = 0;
                Object kfImgNumberObj = redisCacheUtil.getCacheObject("kfImgNumber" + springProfilesActive);
                if (kfImgNumberObj != null) {
                    number = (Integer) kfImgNumberObj;
                    if (number > list.size() || number > (list.size() - 1)) {
                        number = 0;
                    }
                }
                redisCacheUtil.setCacheObject("kfImgNumber" + springProfilesActive, number + 1, 7200);
                keFuQrCode = list.get(number).getPicUrl();

                URL url = new URL(keFuQrCode);
                // 获取链接
                URLConnection conn = url.openConnection();
                // 输入流
                File targetFile = null;

                try (InputStream inStream = conn.getInputStream()) {
                    // 临时文件
                    targetFile = File.createTempFile(UUID.randomUUID().toString(), ".png");
                    java.nio.file.Files.copy(inStream, targetFile.toPath(), StandardCopyOption.REPLACE_EXISTING);

                    WxMediaUploadResult wxMediaUploadResult = weixinService.getMaterialService().mediaUpload(WxConsts.MediaFileType.IMAGE, targetFile);

                    String mediaId = wxMediaUploadResult.getMediaId();

                    if (StringUtils.isNotBlank(mediaId)) {

                        WxMpKefuMessage messageTwo = WxMpKefuMessage.IMAGE().toUser(toUser).mediaId(mediaId).build();
                        weixinService.getKefuService().sendKefuMessage(messageTwo);

                    }
                } catch (IOException e) {
                    e.printStackTrace();
                } finally {
                    // 在JVM退出时删除文件。也可以调用file.delete();立即删除文件。
                    targetFile.deleteOnExit();
                    // 删除临时文件
                    targetFile.delete();
                }
            }
        } catch (WxErrorException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
//        SysGzh sysGzh = platformSysInfo.getSysGzh();
//        String springProfilesActive = sysGzh.getGzhCode();
//        String wxShareImgPath = platformSysInfo.getWxShareImgPath();
//
//        //20200331 循环回复 客服轮播
//        Integer number = 1;
//        Object kfImgNumberObj = redisCacheUtil.getCacheObject("kfImgNumber" + springProfilesActive);
//        if (kfImgNumberObj != null) {
//            number = (Integer) kfImgNumberObj;
//            if (number > 2) {
//                number = 1;
//            }
//        }
//        redisCacheUtil.setCacheObject("kfImgNumber" + springProfilesActive, number + 1, 7200);
//        //20200331 循环回复 客服轮播
//
//        //String clickSendImg = wxShareImgPath + "getTYHF.png";
//        String clickSendImg = wxShareImgPath + number + "kf.png";
//        File resultImg = new File(clickSendImg);
//
//        WxMediaUploadResult wxMediaUploadResult = null;
//        try {
//            wxMediaUploadResult = weixinService.getMaterialService().mediaUpload(WxConsts.MediaFileType.IMAGE, resultImg);
//            String mediaId = wxMediaUploadResult.getMediaId();
//
//            if (StringUtils.isNotBlank(mediaId)) {
//
//                WxMpKefuMessage messageTwo = WxMpKefuMessage.IMAGE().toUser(wxMessage.getFromUser()).mediaId(mediaId).build();
//                weixinService.getKefuService().sendKefuMessage(messageTwo);
//
//            }
//        } catch (WxErrorException e) {
//            e.printStackTrace();
//        }


    }
}
